﻿using System.Windows;
using System.Windows.Input;

namespace SHomeWorkshop.LunarPresentation.Dialogs
{
    /// <summary>
    /// Interaction logic for MarkTextEditor.xaml
    /// </summary>
    public partial class MarkTextEditor : Window
    {
        public MarkTextEditor()
        {
            InitializeComponent();
            topTextBox.Focus();

            Globals.SwitchInputMethod(true);

            //2011年1月30日，因为使上下标式支持辅助线后，实际上其功能就不再是
            //以输入数字为主了。因此，不宜再禁用中文输入。
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
            this.Owner.Focus();
            Globals.SwitchInputMethod(false);
        }

        public string TopMarkText
        {
            get { return topTextBox.Text; }
            set { topTextBox.Text = value; topTextBox.SelectAll(); }
        }

        public string BottomMarkText
        {
            get { return bottomTextBox.Text; }
            set { bottomTextBox.Text = value; }
        }

        private void topTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                this.DialogResult = true;
                this.Owner.Focus();
                this.Close();
                Globals.SwitchInputMethod(false);
            }
            else if (e.Key == Key.Escape)
            {
                this.DialogResult = false;
                this.Owner.Focus();
                this.Close();
                Globals.SwitchInputMethod(false);
            }
        }

        private void bottomTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                this.DialogResult = true;
                this.Owner.Focus();
                this.Close();
                Globals.SwitchInputMethod(false);
            }
            else if (e.Key == Key.Escape)
            {
                this.DialogResult = false;
                this.Owner.Focus();
                this.Close();
                Globals.SwitchInputMethod(false);
            }
        }

        private void bottomTextBox_GotFocus(object sender, RoutedEventArgs e)
        {
            bottomTextBox.SelectAll();
        }
    }
}
